//
//  LGTWalletCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/3.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTWalletCell: UITableViewCell {

    var titleLabel:UILabel?
    var descLabel:UILabel?
    var moneyLabel:UILabel?
    var timeLabel:UILabel?
    
    var _data:Dictionary<String, Any>?
    var slider:UISwitch?
    var data:Dictionary<String, Any>?{
        get{
            return _data
        }
        set{
            _data = newValue
            self.setData()
        }
    }
    
    func setData(){
        self.titleLabel?.text = self.data?["title"] as? String ?? ""
        let json:Dictionary<String, Any> = BaseUtil.baseUtil.getDictionaryFromJSONString(jsonString: self.data?["data"] as? String ?? "")
        self.descLabel?.text = json["title"] as? String ?? ""
        self.timeLabel?.text = self.data?["create_time"] as? String ?? ""
        let money:Int = self.data?["amount"] as? Int ?? 0
        var moneyStr:String = String(format: "%.2f", Double(money) / 100)
        if money >= 0{
            moneyStr = String(format: "+%.2f", Double(money) / 100)
        }
        self.moneyLabel?.text = moneyStr
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(15))
        self.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ (make) in
            make.left.equalTo(SizeFitFloat(12))
            make.height.equalTo(SizeFitFloat(15))
            make.top.equalTo(SizeFitFloat(11))
        })
        
        self.descLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: GrayColor, fontSize: SizeFitFloat(10))
        self.addSubview(self.descLabel!)
        self.descLabel?.snp.makeConstraints({ (make) in
            make.left.equalTo(SizeFitFloat(12))
            make.height.equalTo(SizeFitFloat(10))
            make.top.equalTo(SizeFitFloat(43))
        })
        
        self.timeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: GrayColor, fontSize: SizeFitFloat(10))
        self.addSubview(self.timeLabel!)
        self.timeLabel?.snp.makeConstraints({ (make) in
            make.right.equalTo(-SizeFitFloat(12))
            make.height.equalTo(SizeFitFloat(10))
            make.top.equalTo(SizeFitFloat(43))
        })
        
        self.moneyLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: ColorUtil(color: 0xF94426), fontSize: SizeFitFloat(18))
        self.addSubview(self.moneyLabel!)
        self.moneyLabel?.snp.makeConstraints({ (make) in
            make.right.equalTo(-SizeFitFloat(12))
            make.height.equalTo(SizeFitFloat(18))
            make.top.equalTo(SizeFitFloat(17))
        })
        
        let line:UIImageView = LGTViewCreateUtil.share.createLineView()
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(12))
            make.height.equalTo(1)
            make.right.equalTo(-SizeFit(12))
            make.bottom.equalTo(0)
            make.top.equalTo(56)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
